/**
 * Created with IntelliJ IDEA.
 * Description:山脉数组的峰顶索引
 * User: bjc
 * Date: 2025-11-16
 * Time: 16:20
 */
public class Test05_peakIndexInMountainArray {
    public int peakIndexInMountainArray(int[] arr) {
        int left = 0,right = arr.length-1;
        while(left <= right){
            int mid = left + (right - left) / 2;
            //上升
            if((mid > 0 && arr[mid] > arr[mid-1] && arr[mid] < arr[mid+1])||(arr[mid] < arr[mid+1])) left = mid +1;
            //下降
            else if(arr[mid] < arr[mid-1] && arr[mid] > arr[mid + 1]) right = mid -1;
            else return mid;
        }
        return -1;
    }
}
